package com.ruoyi.web.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.web.controller.sso.domain.AuthNatureUserInfo;
import com.ruoyi.web.domain.IShandongNatureUserInfo;
import com.ruoyi.web.domain.NatureUserInfo;
import com.ruoyi.web.mapper.NatureUserInfoMapper;
import com.ruoyi.web.service.NatureUserInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * description:
 * auth fcb
 * date 2025-05-10 13:24
 **/
@Service
@Slf4j
public class NatureUserInfoServiceImpl extends ServiceImpl<NatureUserInfoMapper, NatureUserInfo> implements NatureUserInfoService {

    @Transactional(rollbackFor = Exception.class)
    public void saveOrUpdateCenterUserInfo(AuthNatureUserInfo natureUserInfo) {
        NatureUserInfo userInfo = this.getById(natureUserInfo.getUuid());
        if(userInfo == null) {
            NatureUserInfo newUserInfo = new NatureUserInfo();
            newUserInfo.setUuid(natureUserInfo.getUuid());
            newUserInfo.setName(natureUserInfo.getName());
            newUserInfo.setMobile(natureUserInfo.getMobile());
            newUserInfo.setLoginName(natureUserInfo.getLoginName());
            newUserInfo.setIsAuth(natureUserInfo.getIsAuth());
            newUserInfo.setEmail(natureUserInfo.getEmail());
            newUserInfo.setCertType(natureUserInfo.getCertType());
            newUserInfo.setCertNo(natureUserInfo.getCertNo());
            newUserInfo.setAuthLevel(natureUserInfo.getAuthLevel());
            newUserInfo.setCreateTime(new Date());
            this.save(newUserInfo);
        }
        else {
            userInfo.setName(natureUserInfo.getName());
            userInfo.setName(natureUserInfo.getName());
            userInfo.setMobile(natureUserInfo.getMobile());
            userInfo.setLoginName(natureUserInfo.getLoginName());
            userInfo.setIsAuth(natureUserInfo.getIsAuth());
            userInfo.setEmail(natureUserInfo.getEmail());
            userInfo.setCertType(natureUserInfo.getCertType());
            userInfo.setCertNo(natureUserInfo.getCertNo());
            userInfo.setAuthLevel(natureUserInfo.getAuthLevel());
            userInfo.setUpdateTime(new Date());
            this.updateById(userInfo);
        }
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void saveOrUpdateIShandongUserInfo(IShandongNatureUserInfo natureUserInfo) {
        NatureUserInfo userInfo = this.getById(natureUserInfo.getUuid());
        if(userInfo == null) {
            NatureUserInfo newUserInfo = new NatureUserInfo();
            newUserInfo.setUuid(natureUserInfo.getUuid());
            newUserInfo.setName(natureUserInfo.getName());
            newUserInfo.setMobile(natureUserInfo.getMobile());
            newUserInfo.setLoginName(natureUserInfo.getLoginname());
            newUserInfo.setIsAuth(natureUserInfo.getIsAuth());
            newUserInfo.setEmail(natureUserInfo.getEmail());
            newUserInfo.setAuthLevel(natureUserInfo.getAuthlevel());
            newUserInfo.setCode(natureUserInfo.getCode());
            newUserInfo.setIsalipay(natureUserInfo.getIsalipay());
            newUserInfo.setNation(natureUserInfo.getNation());
            newUserInfo.setHeadportraitpath(natureUserInfo.getHeadportraitpath());
            newUserInfo.setNewauthlevel(natureUserInfo.getNewauthlevel());
            newUserInfo.setPost(natureUserInfo.getPost());
            newUserInfo.setAppmark(natureUserInfo.getAppmark());
            newUserInfo.setIsauthuser(natureUserInfo.getIsauthuser());
            newUserInfo.setNickname(natureUserInfo.getNickname());
            newUserInfo.setResidence(natureUserInfo.getResidence());
            newUserInfo.setPaperstype(natureUserInfo.getPaperstype());
            newUserInfo.setLogintime(natureUserInfo.getLogintime());
            newUserInfo.setAddress(natureUserInfo.getAddress());
            newUserInfo.setRegtime(natureUserInfo.getRegtime());
            newUserInfo.setSex(natureUserInfo.getSex());
            newUserInfo.setCardendtime(natureUserInfo.getCardendtime());
            newUserInfo.setRegsource(natureUserInfo.getRegsource());
            newUserInfo.setCardstarttime(natureUserInfo.getCardstarttime());
            newUserInfo.setRegisteredresidence(natureUserInfo.getRegisteredresidence());
            newUserInfo.setNewregtime(natureUserInfo.getNewregtime());
            newUserInfo.setIswx(natureUserInfo.getIswx());
            newUserInfo.setPapersnumber(natureUserInfo.getPapersnumber());
            newUserInfo.setCreateTime(new Date());
            this.save(newUserInfo);
        }
        else {
            userInfo.setName(natureUserInfo.getName());
            userInfo.setName(natureUserInfo.getName());
            userInfo.setMobile(natureUserInfo.getMobile());
            userInfo.setLoginName(natureUserInfo.getLoginname());
            userInfo.setIsAuth(natureUserInfo.getIsAuth());
            userInfo.setEmail(natureUserInfo.getEmail());
            userInfo.setAuthLevel(natureUserInfo.getAuthlevel());
            userInfo.setCode(natureUserInfo.getCode());
            userInfo.setIsalipay(natureUserInfo.getIsalipay());
            userInfo.setNation(natureUserInfo.getNation());
            userInfo.setHeadportraitpath(natureUserInfo.getHeadportraitpath());
            userInfo.setNewauthlevel(natureUserInfo.getNewauthlevel());
            userInfo.setPost(natureUserInfo.getPost());
            userInfo.setAppmark(natureUserInfo.getAppmark());
            userInfo.setIsauthuser(natureUserInfo.getIsauthuser());
            userInfo.setNickname(natureUserInfo.getNickname());
            userInfo.setResidence(natureUserInfo.getResidence());
            userInfo.setPaperstype(natureUserInfo.getPaperstype());
            userInfo.setLogintime(natureUserInfo.getLogintime());
            userInfo.setAddress(natureUserInfo.getAddress());
            userInfo.setRegtime(natureUserInfo.getRegtime());
            userInfo.setSex(natureUserInfo.getSex());
            userInfo.setCardendtime(natureUserInfo.getCardendtime());
            userInfo.setRegsource(natureUserInfo.getRegsource());
            userInfo.setCardstarttime(natureUserInfo.getCardstarttime());
            userInfo.setRegisteredresidence(natureUserInfo.getRegisteredresidence());
            userInfo.setNewregtime(natureUserInfo.getNewregtime());
            userInfo.setIswx(natureUserInfo.getIswx());
            userInfo.setPapersnumber(natureUserInfo.getPapersnumber());
            userInfo.setUpdateTime(new Date());
            this.updateById(userInfo);
        }
    }
}
